//
//  WYDirectMailHeadView.m
//  CirclePush
//
//  Created by admin on 2018/4/25.
//  Copyright © 2018年 admin. All rights reserved.
//

#import "WYDirectMailHeadView.h"
#import "WYDirectCommonView.h"
@implementation WYDirectMailHeadView

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        //
        [self createSubViews];
        self.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    }
    return self;
}

- (void)createSubViews {
    // 头图片
    self.headImageView = [[UIImageView alloc]init];
    self.headImageView.backgroundColor = [UIColor whiteColor];
    //self.headImageView.image = [UIImage imageNamed:@"登录_背景图"];
    self.headImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.headImageView.clipsToBounds = YES;
    [self addSubview:self.headImageView];
    [self.headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, 200*DUP));
    }];
    // 预约广告申请
    self.advertisingView = [[UIView alloc] init];
    self.advertisingView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.advertisingView];
    [self.advertisingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.headImageView.mas_bottom).with.offset(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, SYRealValue(440 / 2)));
    }];
    // 底部线
    UIView *advertisingViewLineView = [[UIView alloc] init];
    advertisingViewLineView.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    [self.advertisingView addSubview:advertisingViewLineView];
    [advertisingViewLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, SYRealValue(10 / 2)));
    }];
    // 预约投广告申请
    WYDirectCommonView *directCommonView_01 = [[WYDirectCommonView alloc]init];
    directCommonView_01.TitleLabel.text = @"预约投广告申请";
    [self.advertisingView addSubview:directCommonView_01];
    [directCommonView_01 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, SYRealValue(80 / 2)));
    }];
    UIView *directCommonView_01LineView = [[UIView alloc] init];
    directCommonView_01LineView.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    [directCommonView_01 addSubview:directCommonView_01LineView];
    [directCommonView_01LineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, [UIScreen mainScreen].scale / 2));
    }];
    // 联系人
    UILabel *linkManTextFieldLeftLabel = [[UILabel alloc] init];
    linkManTextFieldLeftLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    linkManTextFieldLeftLabel.text = @"联系人";
    linkManTextFieldLeftLabel.textAlignment = NSTextAlignmentRight;
    linkManTextFieldLeftLabel.textColor = [UIColor blackColor];
    [self.advertisingView addSubview:linkManTextFieldLeftLabel];
    [linkManTextFieldLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(directCommonView_01.mas_bottom).with.offset(SYRealValue(40 / 2));
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SYRealValue(150 / 2), SYRealValue(80 / 2)));
    }];
    //
    self.linkManTextField = [[UITextField alloc] init];
    self.linkManTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.linkManTextField.backgroundColor = [UIColor whiteColor];
    self.linkManTextField.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    //linkManTextField.placeholder = @"请输入您的姓名";
    //[linkManTextField setValue:[UIFont systemFontOfSize:SYRealValue(36 / 2)] forKeyPath:@"_placeholderLabel.font"];
    self.linkManTextField.returnKeyType = UIReturnKeyDone;
    self.linkManTextField.keyboardType = UIKeyboardTypeDefault;
    self.linkManTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.linkManTextField.leftViewMode = UITextFieldViewModeAlways;
    self.linkManTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.linkManTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self.advertisingView addSubview:self.linkManTextField];
    [self.linkManTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
    [self.linkManTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(directCommonView_01.mas_bottom).with.offset(SYRealValue(40 / 2));
        make.left.equalTo(linkManTextFieldLeftLabel.mas_right).with.offset(SYRealValue(20 / 2));
        make.right.mas_equalTo(-SYRealValue(20 / 2));
        make.height.mas_equalTo(SYRealValue(80 / 2));
    }];
    // 联系电话
    UILabel *linkManPhoneTextFieldLeftLabel = [[UILabel alloc] init];
    linkManPhoneTextFieldLeftLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    linkManPhoneTextFieldLeftLabel.text = @"联系电话";
    linkManPhoneTextFieldLeftLabel.textAlignment = NSTextAlignmentRight;
    linkManPhoneTextFieldLeftLabel.textColor = [UIColor blackColor];
    [self.advertisingView addSubview:linkManPhoneTextFieldLeftLabel];
    [linkManPhoneTextFieldLeftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.linkManTextField.mas_bottom).with.offset(SYRealValue(25 / 2));
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(SYRealValue(150 / 2), SYRealValue(80 / 2)));
    }];
    //
    self.linkPhoneManTextField = [[UITextField alloc] init];
    self.linkPhoneManTextField.borderStyle = UITextBorderStyleRoundedRect;
    self.linkPhoneManTextField.backgroundColor = [UIColor whiteColor];
    self.linkPhoneManTextField.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    //linkManTextField.placeholder = @"请输入您的姓名";
    //[linkManTextField setValue:[UIFont systemFontOfSize:SYRealValue(36 / 2)] forKeyPath:@"_placeholderLabel.font"];
    self.linkPhoneManTextField.returnKeyType = UIReturnKeyDone;
    self.linkPhoneManTextField.keyboardType = UIKeyboardTypeNumberPad;
    self.linkPhoneManTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
    self.linkPhoneManTextField.leftViewMode = UITextFieldViewModeAlways;
    self.linkPhoneManTextField.autocorrectionType = UITextAutocorrectionTypeNo;
    self.linkPhoneManTextField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    [self.advertisingView addSubview:self.linkPhoneManTextField];
    [self.linkPhoneManTextField addTarget:self action:@selector(textFieldDidEditing:) forControlEvents:UIControlEventEditingChanged];
    [self.linkPhoneManTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.linkManTextField.mas_bottom).with.offset(SYRealValue(25 / 2));
        make.left.equalTo(linkManPhoneTextFieldLeftLabel.mas_right).with.offset(SYRealValue(20 / 2));
        make.right.mas_equalTo(-SYRealValue(20 / 2));
        make.height.mas_equalTo(SYRealValue(80 / 2));
    }];
    // 确定按钮
    UIButton *sureButton = [[UIButton alloc]init];
    sureButton.backgroundColor = [UIColor blueColor];
    [sureButton setTitle:@"确定" forState:UIControlStateNormal];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(30 / 2)];
    [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    sureButton.layer.masksToBounds = YES;
    sureButton.layer.cornerRadius = 5.f;
    [sureButton addTarget:self action:@selector(sureButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.advertisingView addSubview:sureButton];
    [sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.linkPhoneManTextField.mas_bottom).with.offset(SYRealValue(25 / 2));
        make.centerX.equalTo(self.advertisingView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(SYRealValue(250 / 2), SYRealValue(70 / 2)));
    }];
    // 服务流程
    self.serviceProcessImageView = [[UIImageView alloc]init];
    self.serviceProcessImageView.image=[UIImage imageNamed:@"service"];
    //self.serviceProcessImageView.image = [UIImage imageNamed:@"登录_背景图"];
    self.serviceProcessImageView.backgroundColor = [UIColor whiteColor];
    self.serviceProcessImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.serviceProcessImageView.clipsToBounds = YES;
    [self addSubview:self.serviceProcessImageView];
    [self.serviceProcessImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.advertisingView.mas_bottom).with.offset(0);
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.height.mas_equalTo((kScreenWidth)/1.64);
    }];
    // 底部图片
    self.bottomImageView = [[UIImageView alloc]init];
    self.bottomImageView.image = [UIImage imageNamed:@"TestImage1"];
    //self.serviceProcessImageView.image = [UIImage imageNamed:@"登录_背景图"];
    self.bottomImageView.contentMode = UIViewContentModeScaleAspectFit;
    self.bottomImageView.clipsToBounds = YES;
    [self addSubview:self.bottomImageView];
    [self.bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.serviceProcessImageView.mas_bottom).with.offset(10);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, 125*DUP));
    }];
    // 上刊成功案例
    WYDirectCommonView *directCommonView_02 = [[WYDirectCommonView alloc]init];
    directCommonView_02.TitleLabel.text = @"上刊成功案例";
    [self addSubview:directCommonView_02];
    [directCommonView_02 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bottomImageView.mas_bottom).with.offset(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, SYRealValue(80 / 2)));
    }];
    UIView *directCommonView_02LineView = [[UIView alloc] init];
    directCommonView_02LineView.backgroundColor = [UIColor hexStringToColor:@"#f4f4f4" alpha:1.0];
    [directCommonView_02 addSubview:directCommonView_02LineView];
    [directCommonView_02LineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(0);
        make.left.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(ScreenWidth, [UIScreen mainScreen].scale / 2));
    }];
}

- (void)textFieldDidEditing:(UITextField *)textField {
    if (textField == self.linkManTextField) {
        NSLog(@"%@",self.linkManTextField.text);
    }
    else
    {
        NSLog(@"%@",self.linkPhoneManTextField.text);
    }
}

- (void)sureButtonAction:(UIButton *)sender
{
    if (self.complete) {
        self.complete(self.linkManTextField.text, self.linkPhoneManTextField.text);
    }
    
    
    NSLog(@"确定");
}


@end
